package finance

import org.apache.commons.math.random.RandomDataImpl
import org.apache.commons.math.stat.StatUtils

class NoiseService {

    static transactional = true

    def add(vals, factor) {
        if( factor == 0 ) {
            return vals
        }
        
        def rdi = new RandomDataImpl()
        def range = factor * StatUtils.variance(vals as double[]) 
        
        return vals.collect {  it + rdi.nextUniform(0, range) }
    }
}
